<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm">
      <el-form-item label="直播员:">
        <el-autocomplete
          v-model="liveUserLabel"
          :fetch-suggestions="querySearchAsync"
          placeholder="请输入用户昵称"
          @select="handleSelect"
        ></el-autocomplete>
      </el-form-item>
      <el-form-item label="首页直播观看地址:">
        <el-input v-model="dataForm.liveUrl" placeholder="首页直播观看地址" clearable></el-input>
      </el-form-item>
      <el-form-item label="首页直播推流地址:">
        <el-input v-model="dataForm.pushUrl" placeholder="首页直播推流地址" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="update()">更新</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  export default {
    data () {
      return {
        liveUserLabel: '',
        dataForm: {
          liveUrl: '',
          pushUrl: '',
          liveUser: ''
        }
      }
    },
    components: {
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.$http({
          url: this.$http.adornUrl('/sys/live/info'),
          method: 'get'
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataForm.liveUrl = data.liveConfig.liveUrl || ''
            this.dataForm.pushUrl = data.liveConfig.pushUrl || ''
          } else {
            this.$message.error(data.msg)
          }
        })
      },
      handleSelect (item) {
        this.dataForm.liveUser = item.userId
      },
      querySearchAsync (query, cb) {
        this.$http({
          url: this.$http.adornUrl(`/sys/member/list/${query}`),
          method: 'get'
        }).then(({data}) => {
          if (data && data.code === 0) {
            console.log('userList >>>>>>>>>>>>>>>', data.userList)
            cb(data.userList)
          } else {
            this.$message.error(data.msg)
          }
        })
      },
      update: function () {
        this.$http({
          url: this.$http.adornUrl(`/sys/live/update`),
          method: 'post',
          data: this.$http.adornData({
            'liveUrl': this.dataForm.liveUrl,
            'pushUrl': this.dataForm.pushUrl,
            'liveUser': this.dataForm.liveUser
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          } else {
            this.$message.error(data.msg)
          }
        })
      }
    }
  }
</script>
